#!/bin/python3
#-*- coding: utf-8 -*-
# my_install.py
# @author 刘秋
# @email lq@aqiu.info
# @description 
# @created 2020-04-04T09:50:34.149Z+08:00
# @last-modified 2020-04-04T16:10:15.754Z+08:00
#

import os
import shutil
import datetime
import numpy as np
import pandas as pd

path_list = [r"E:\Download",r"\\LQNAS\Nas\Download"]
new_folder_path = r"\\LQNAS\install\压缩包"
i_folder_path=r"\\LQNAS\install\5.安装包"
word_folder_path=r"\\LQNAS\Nas\PDF"
compress_type_list=["zip","rar","7z"]
i_type_list = ["exe","msi"]
word_type_list =["pdf","docx","doc","xls","xlsx","ppt","pptx"]

if not os.path.exists(new_folder_path):
    os.makedirs(new_folder_path)


def my_os_remove(path,name):    
    try:
        shutil.move(os.path.join(path,name),word_folder_path)
    except shutil.Error as err:                        
        print(f"这个包{os.path.join(path,name)}有问题")
        print(err)
        new_time=datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
        new_name=str(new_time)+"_"+name
        os.rename(os.path.join(path,name),os.path.join(path,new_name))
        print(f"旧的名字:{name}==>>新的名字：{new_name}")
        my_os_remove(path,new_name)
        raise err
        # if os.path.exists(os.path.join(path,name)):
        #     os.remove(os.path.join(path,name))

for path in path_list:
    for name in os.listdir(path):
        if name.split(".")[-1] in compress_type_list:
            print(f"{os.path.join(path,name)}是一个压缩包")
            try:
                my_os_remove(path,name)
            except shutil.Error as err:
                pass
            
        elif name.split(".")[-1] in i_type_list:
            print(f"{os.path.join(path,name)}是一个安装包")
            try:
                my_os_remove(path,name)
            except shutil.Error as err:
                pass
            
        elif name.split(".")[-1] in word_type_list:
            print(f"{os.path.join(path,name)}是一个文档")
            try:
                my_os_remove(path,name)
            except shutil.Error as err:
                pass
                            
        elif name.split(".")[-1] == "torrent":
            print(f"{os.path.join(path,name)}是一个零时文件")
            if os.path.exists(os.path.join(path,name)):
                os.remove(os.path.join(path,name))
            